
<fieldset>
	<legend>Custom Search Form</legend>
	<form id="nform" style="width: 500px ; float:left;">
		Search Name : <input type="text" name="nsearch" id="nsearch" value="" autocomplete="off"/><input type="submit" value="Search" />
	</form>
</fieldset>
<table id="flex1" style="display:none"></table>

<script type="text/javascript">
$(document).ready(function(){
   
   <?php echo $js_grid; ?>
function test(com,grid)
{
    if (com=='Select All')
    {
		$('.bDiv tbody tr',grid).addClass('trSelected');
    }
    
    if (com=='DeSelect All')
    {
		$('.bDiv tbody tr',grid).removeClass('trSelected');
    }
    
    if (com=='Delete')
        {
           if($('.trSelected',grid).length>0){
			   if(confirm('Delete ' + $('.trSelected',grid).length + ' items?')){
		            var items = $('.trSelected',grid);
		            var itemlist ='';
		        	for(i=0;i<items.length;i++){
						itemlist+= items[i].id.substr(3)+",";
					}
					$.ajax({
					   type: "POST",
					   url: "<?php site_url("/ajax/deletec");?>",
					   data: "items="+itemlist,
					   success: function(data){
					   	$('#flex1').flexReload();
					  	alert(data);
					   }
					});
				}
			} else {
				return false;
			} 
        }          
}

//This function adds paramaters to the post of flexigrid.
// You can add a verification as well by return to false if you don't want flexigrid to submit			
function addFormData(){
	//passing a form object to serializeArray will get the valid data from all the objects, but, 
//if the you pass a non-form object, you have to specify the input elements that the data will come from
	var dt = $('#sform').serializeArray();
	$("#flex1").flexOptions({params: dt});
	//$('#flex1').flexOptions({params:[{name:'param1', value: 'val1'}, {name:'param2', value: 'val2'}]});
	return true;
}
	
$('#sform').submit(function (){
    var dt = $('#sform').serializeArray();
	$("#flex1").flexOptions({params: dt});
	$('#flex1').flexOptions({newp: 1}).flexReload();
	return false;
});
$('#nform').submit(function (){
    var dt = $('#nform').serializeArray();
    var qr = $('#nsearch').val();
	$("#flex1").flexOptions({params: dt});
	$('#flex1').flexOptions({url: "<?php echo base_url(); ?>index.php/ajax/search"});
	$('#flex1').flexOptions({qtype:"name"});
	$('#flex1').flexOptions({query: qr});
	$('#flex1').flexOptions({newp: 1}).flexReload();
	return false;
});

    
});
</script>